import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class Server 
{
	public static void main(String[] args) throws IOException 
	{	
		new Server();	
	}

	public Server() 
	{
		//We need a try-catch because lots of errors can be thrown
		try 
		{
			ServerSocket sSocket = new ServerSocket(1337);
			System.out.println("Server started");

			while(true) 
			{
				Socket socket = sSocket.accept();

				BufferedWriter output = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
				BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));

				output.write("You have connected");
 
				String chatInput = input.readLine();
				System.out.println(chatInput + "\n");
			}
		} 
		catch(IOException exception) 
		{
			System.out.println("Error: " + exception);
		}
	}
}
